from pysqlite2 import dbapi2 as sqlite

persons = [
    ("Hugo", "Boss", 33),
    ("Calvin", "Klein", 45)
    ]

con = sqlite.connect(":memory:")

# Create the table
con.execute("create table person(firstname, lastname, age)")

# Fill the table
con.executemany("insert into person(firstname, lastname, age) values (?, ?, ?)", persons)

# Print the table contents
for row in con.execute("select firstname, lastname, age from person"):
    print row

# Using a dummy WHERE clause to not let SQLite take the shortcut table deletes.
#print "I just deleted", con.execute("delete from person where 1=1").rowcount, "rows" 


#con = sqlite.connect("mydb")
con.row_factory = sqlite.Row
cur = con.cursor()
"""
cur.executescript('''
    create table person(
        firstname,
        lastname,
        age
    );

    create table book(
        title,
        author,
        published
    );

    insert into book(title, author, published)
    values (
        'Dirk Gently''s Holistic Detective Agency',
        'Douglas Adams',
        1987
    );
    ''') 
"""

cur.execute("select firstname, lastname from person")
for row in cur:
    print row["lastname"]
    assert row[0] == row["firstname"]
    #assert row["lastname"] == row["nAmE_lAsT"]
    #assert row[2] == row["age"]
    #assert row[2] == row["AgE"] 
